 <? include("/inc/header.html") {} ?>
 
 <div class="col-lg-5">
   	<div class="panel" overflow: auto;">
          <div class="panel-body pan "style="width:auto; overflow: auto;" >
			<div class="form-body pal" style="float:left;width:100%; overflow: auto;"  >
			<div>
					<label for="inputUsername" class="col-md-3 control-label">
				 		<div align="right">范围
							<span class='require' id="paixu">*</span></div>
                   	 </label>
						<div class="col-md-9">
							<div class="input-icon">
								<select id="scope" class="form-control">
									<option value="0">全库有效</option>
									<option value="1">单库有效</option>
								</select>
							</div>
						</div>
					</div>
					<div id="showrequire" style="display: none;">
					<label for="inputUsername" class="col-md-3 control-label">所属类
						<span class='require' id="paixu">*</span> </label>
					<div class="col-md-9">
						<div class="input-group input-group-sm mbs" >
							 <input id="parentclassname" type="text" placeholder="请选择类"  class="form-control" disabled="true"  />
							  <span class="input-group-btn"><button id="buttonid" onclick="saveclassZTree()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择类..</button></span>		
						</div>
					</div>
				</div>
				<div>
					<label for="inputUsername" class="col-md-3 control-label">
					  <div align="right">中文名称
						<span class='require' id="zhongwenName">*</span></div>
                    </label>
					<div class="col-md-7">
						<div class="input-icon" >
							<select id="nameZh" class="form-control" onchange="setEnName(this);">
								
							</select>
						</div>
					</div>
				</div>
				<div>
					<label for="inputUsername" class="col-md-3 control-label">
					  <div align="right">英文名称
						<span class='require' id="yingwenName">*</span></div>
                    </label>
					<div class="col-md-7">
						<div class="input-icon">
							<select id="nameEn" class="form-control" disabled="disabled">
								
							</select>
						</div>
					</div>
				</div>
<!-- 					<div> -->
<!-- 					<label for="inputUsername" class="col-md-3 control-label"> -->
<!-- 				 		<div align="right">是否公共字段 -->
<!-- 							<span class='require' id="paixu">*</span></div> -->
<!--                    	 </label> -->
<!-- 						<div class="col-md-9"> -->
<!-- 							<div class="input-icon"> -->
<!-- 								<select id="commonality" class="form-control"> -->
<!-- 									<option value="0">是</option> -->
<!-- 									<option value="1">否</option> -->
<!-- 								</select> -->
<!-- 							</div> -->
<!-- 						</div> -->
<!-- 					</div> -->
					
						<div>
						<label for="inputUsername" class="col-md-3 control-label">
						  <div align="right">权重值
							<span class='require' id="yingwenName">*</span></div>
	                    </label>
						<div class="col-md-7">
							<div class="input-icon">
								<input id="weighted" type="text"  class="form-control"  />
							</div>
						</div>
					</div>
				
				<input id="parentClassid" type="hidden" value="" class="form-control" />
                <input id="mainid" type="hidden"  class="form-control" /> 
			</div>
		</form>
	</div>
  </div>
</div>
<script type="text/javascript">
	var id = window.parent.getfieldId();
	var classesZh = window.parent.getcname();
	var fieldaddupds = window.parent.getfieldaddupds();
	var fieldcurr = window.parent.getfieldcurr();
	if(id !=0){
		$.ajax({
			type : "post",
			url : "fieldAddUploadQuery.do",
			dataType : "json",
			data:{
				"id":id
			},
			beforeSend : function(XMLHttpRequest) {},
			success: function(data) {
           		
//            		$("#commonality").val(data[0].isCommonDataProperty);
           		 $("#scope").val(data.range);
           		 $("#weighted").val(data.heightValue);
           		 $("#parentClassid").val(data.classesEn);
           		 $("#parentclassname").val(classesZh);
           		 if(data.range == '1'){
           		 	$("#showrequire").show();
           		 	xianshidata();
           		 }else{
           		 	listCustomFields();
           		 }
           		 $("#nameZh").val(data.nameZh);
           		 $("#nameEn").val(data.nameEn);
           		 if(fieldaddupds == 1){
           			 document.getElementById('nameZh').disabled = true;
           			 document.getElementById('buttonid').disabled = true;
           			 document.getElementById('nameEn').disabled = true;
//            			 document.getElementById('commonality').disabled = true;
           			 document.getElementById('scope').disabled = true;
           			 document.getElementById('weighted').disabled = true;
           			 document.getElementById('parentClassid').disabled = true;
           			 document.getElementById('parentclassname').disabled = true;
           		 }
    		}
		});
	}
	function save(){  
		$.ajax({
			type : "post",
			url : "./fieldAddUpload.do",
			dataType : "json",
			data:{
				"nameZh":$("#nameZh").val(),
				"nameEn":$("#nameEn").val(),
// 				"commonality":$("#commonality").val(),
				"range":$("#scope").val(),
				"heightValue":$("#weighted").val(),
				"classesEn":$("#parentClassid").val(),
				"id":id,
			},
			beforeSend : function(XMLHttpRequest) {},
			success: function(data) {
           		 var index = parent.layer.getFrameIndex(window.name); 
           		 window.parent.fieldList(fieldcurr);
           		if(data == 'yes'){
           			if(id != 0){
           				parent.layer.msg('修改成功！');
           			}else{
           				parent.layer.msg('添加成功！');
           			}
           		}else if(data == 'exist'){
           			parent.layer.msg('请勿重复添加权重字段!');
           		}
           		else{
           			if(id != 0){
           				parent.layer.msg('修改失败！');
           			}else{
           				parent.layer.msg('添加失败！');
           			}
           		}
            	 parent.layer.close(index); 
    		}
			});
    } 
    //查询类
    function saveclassZTree() {
		parent.layer.open({
			type : 2,
			area : [ '360px', '400px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"选择父节点",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["search-weight-classes-zTree.html?winName="+window.name, 'no'],
			yes : function(index,layer) {	
	   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			   iframeWin.save();
			   xianshidata();
			},
			cancel : function(index) {
			}
		});
	};
	//判断范围
	$(document).ready(function () { 
		  $("#scope").bind("change",function(){ 
		  	$("#nameZh").html("");
			$("#nameEn").html("");
		    if($(this).val()==1){
		   		$("#showrequire").show();
		    }else{
		    	$("#showrequire").hide();
		    	$("#parentClassid").val("");
		    	$("#parentclassname").val("");
		    	listCustomFields(); 
		    }
		    
		  }); 
		  listCustomFields();
		});
	
	function listCustomFields(){
		$.ajax({
					type : "post",
					url : "./listAllCommonDataCnAndEnName.do",
					dataType : "json",
					async : false,
					success : function(data) {
						var fieldCnName = '';
						var fieldEnName = '';
						for ( var i = 0; i < data.length; i++) {
							fieldCnName += '<option value="'+data[i].nameZh+'" name="'+data[i].nameEn+'">'+data[i].nameZh+'</option>';
							fieldEnName += '<option value="'+data[i].nameEn+'">'+data[i].nameEn+'</option>';
						}
						$("#nameZh").html(fieldCnName);
						$("#nameEn").html(fieldEnName);
					},
					error : function(data) {
						alert("请求失败");
					}
				});
		
	}
	function xianshidata() {
		$.ajax({
					type : "post",
					url : "./KnowledgeDataPropertyList.do",
					data : {
						"lid" : $("#parentClassid").val()
					},
					dataType : "json",
					async : false,
					success : function(data) {
						var fieldCnName = '';
						var fieldEnName = '';
						for ( var i = 0; i < data.length; i++) {
							fieldCnName += '<option value="'+data[i].name+'" name="'+data[i].nameen+'">'+data[i].name+'</option>';
							fieldEnName += '<option value="'+data[i].nameen+'">'+data[i].nameen+'</option>';
						}
						$("#nameZh").html(fieldCnName);
						$("#nameEn").html(fieldEnName);
					},
					error : function(data) {
						alert("请求失败");
					}
				});

	}
	function setEnName(obj){
		$("#nameEn").val($("option[value='"+obj.value+"']").attr("name"));
	}
		function gaun(){
			 var index = parent.layer.getFrameIndex(window.name); 
            	 parent.layer.close(index); 
		}
</script>

